<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* 
*/
class Venue extends MY_Controller
{
	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->model('User/VenueModel','venue');
	}

	//列表页
	public function index()
	{
		$this->load->view('venue_list');
	}


	//获取列表数据
	public function get_list()
	{
		$res = $this->venue->get_list_data();

		if ($res) 
		{
			$data['list'] = $res;
			$data['status'] = 200;
			$data['message'] = '获取成功！';
		}
		else
		{
			$data['status'] = 400;
			$data['message'] = '数据获取失败！';
		}

		echo json_encode($data);exit();
	}


	//添加、编辑页
	public function venue_info()
	{
		$data['venue_id'] = intval($this->uri->segment(3));
		
		//编辑
		if ($data['venue_id'] > 0) 
		{
			$res = $this->venue->get_venue_row($data['venue_id']);
		}

		$data['name'] = isset($res['name']) ? $res['name'] : '';
		$data['mobile'] = isset($res['mobile']) ? $res['mobile'] : '';
		$data['address'] = isset($res['address']) ? $res['address'] : '';

		$this->load->view('venue_info', $data);
	}


	//提交入库
	public function insert_venue()
	{
		$field = array('name','address','mobile');

		$arr = $this->input->post($field, TRUE);

		$venue_id = $this->input->post('venue_id');

		//添加
		if (empty($venue_id)) 
		{
			$res = $this->venue->inser_venue_data($arr);

			if ($res) 
			{
				$data['status'] = 200;
				$data['message'] = '添加成功！';

			}
			else
			{
				$data['status'] = 400;
				$data['message'] = '添加失败！';
			}
		}
		//更新
		else
		{
			$res = $this->venue->updata_venue_data($arr,$venue_id);

			if ($res) 
			{
				$data['status'] = 200;
				$data['message'] = '更新成功！';

			}
			else
			{
				$data['status'] = 400;
				$data['message'] = '更新失败！';
			}

		}

		echo json_encode($data);exit();

	}


	//删除
	public function delete_venue()
	{
		$venue_id = $this->input->get('id', true);

		$res = $this->venue->remove_venue($venue_id);

		if ($res){
			$data['status'] = 200;
			$data['message'] = '删除成功！';
		}
		else{
			$data['status'] = 400;
			$data['message'] = '删除失败！';
		}

		echo json_encode($data);exit();

	}

}



?>